//
//  ScreenAccess.m
//  models
//
//  Created by minfo on 13-4-24.
//  Copyright (c) 2013年 minfo. All rights reserved.
//

#import "ScreenAccess.h"
#import "SBJson.h"
#import "Common.h"
#import "ASIDownloadCache.h"

@implementation ScreenAccess
#define APP_URL @"http://itunes.apple.com/lookup?id=650748921"





//帮助接口
- (ASIHTTPRequest*)ASIGetNewsByGroupID:(int)GroupID
{
    NSMutableString* postURL=[[Common alloc]GetWebAPI:@"help.aspx"];
//    [postURL appendFormat:@"user-id=%@",[[Common alloc]GetMobile]];
     [postURL appendFormat:@"user-id=%@",[Common GetPhone]];
    [postURL appendFormat:@"&helpid=%d",1];
    [postURL appendFormat:@"&user-coop=%@",[[Common alloc]GetUserCoop]];
     [postURL appendFormat:@"&password-coop=%@",[[Common alloc]GetApipwd]];
    NSURL *url = [NSURL URLWithString:postURL];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    request.defaultResponseEncoding=NSUTF8StringEncoding;
    [request setDownloadCache:[ASIDownloadCache sharedCache]];
    [request setCachePolicy:ASIFallbackToCacheIfLoadFailsCachePolicy|ASIAskServerIfModifiedWhenStaleCachePolicy];
    [request setSecondsToCache:60*60*24*7]; // Cache for 30 days
    [request setTimeOutSeconds:30];
    [request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
    [request startAsynchronous];
    return request;
   
}
//首页广告接口
- (ASIHTTPRequest*)ASIHomerecommend
{
    NSMutableString* postURL=[[Common alloc]GetWebAPI:@"homerecommend2.aspx"];
//    [postURL appendFormat:@"user-id=%@",[[Common alloc]GetMobile]];
    [postURL appendFormat:@"user-id=%@",[Common GetPhone]];
    [postURL appendFormat:@"location=%@",[[Common alloc] GetLocation]];
    [postURL appendFormat:@"&user-coop=%@",[[Common alloc]GetUserCoop]];
    [postURL appendFormat:@"&password-coop=%@",[[Common alloc]GetApipwd]];
    NSURL *url = [NSURL URLWithString:postURL];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    request.defaultResponseEncoding=NSUTF8StringEncoding;
    [request setDownloadCache:[ASIDownloadCache sharedCache]];
    [request setCachePolicy:ASIFallbackToCacheIfLoadFailsCachePolicy|ASIAskServerIfModifiedWhenStaleCachePolicy];
    [request setSecondsToCache:60*60*24]; // Cache for 30 days
    [request setTimeOutSeconds:30];
    [request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
    [request startAsynchronous];
    return request;
    
}



//首页天气接口

- (ASIHTTPRequest*)ASIGetHomePageWeatherByCity{
    NSMutableString* postURL=[[Common alloc] GetWebAPI:@"weather.aspx"];
    [postURL appendFormat:@"location=%@",[[Common alloc] GetLocation]];
    [postURL appendFormat:@"&user-coop=%@",[[Common alloc] GetUserCoop]];
    [postURL appendFormat:@"&password-coop=%@",[[Common alloc] GetApipwd]];
    
    NSURL *url=[NSURL URLWithString:postURL];
    ASIHTTPRequest *request=[ASIHTTPRequest requestWithURL:url];
    request.defaultResponseEncoding=NSUTF8StringEncoding;
    [request setDownloadCache:[ASIDownloadCache sharedCache]];
    [request setCachePolicy:ASIFallbackToCacheIfLoadFailsCachePolicy|ASIAskServerIfModifiedWhenStaleCachePolicy];
    [request setSecondsToCache:60*60*24*7]; // Cache for 30 days
    [request setTimeOutSeconds:30];
    [request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
    [request startAsynchronous];
    return request;
    
}
//搜索接口
- (ASIHTTPRequest*)ASIGetSearch:(NSString *)keyWord Start:(int)start Limit:(int)limit{
    NSMutableString* postURL=[[Common alloc] GetWebAPI:@"search2.aspx"];
    [postURL appendFormat:@"location=%@",[[Common alloc] GetLocation]];
      [postURL appendFormat:@"&query=%@",[[Common alloc] GetEncode:keyWord]];
    [postURL appendFormat:@"&user-coop=%@",[[Common alloc] GetUserCoop]];
    [postURL appendFormat:@"&password-coop=%@",[[Common alloc] GetApipwd]];
//     [postURL appendFormat:@"&user-id=%@",[[Common alloc]GetMobile]];
    [postURL appendFormat:@"&user-id=%@",[Common GetPhone]];
    [postURL appendFormat:@"&start=%d",start];
    [postURL appendFormat:@"&limit=%d",limit];
  
    NSURL *url=[NSURL URLWithString:postURL];
    ASIHTTPRequest *request=[ASIHTTPRequest requestWithURL:url];
    request.defaultResponseEncoding=NSUTF8StringEncoding;
//    [request setDownloadCache:[ASIDownloadCache sharedCache]];
    [request setTimeOutSeconds:30];
//    [request setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy];
    [request startAsynchronous];
    return request;
    
}


//意见反馈接口
- (ASIHTTPRequest*)ASIOpinion:(NSString *)opinion{
    NSMutableString* postURL=[[Common alloc] GetWebAPI:@"opinion.aspx"];
    [postURL appendFormat:@"opinion=%@",[[Common alloc] GetEncode:opinion]];
    [postURL appendFormat:@"&user-coop=%@",[[Common alloc] GetUserCoop]];
    [postURL appendFormat:@"&password-coop=%@",[[Common alloc] GetApipwd]];
//    [postURL appendFormat:@"&user-id=%@",[[Common alloc]GetMobile]];
    [postURL appendFormat:@"&user-id=%@",[Common GetPhone]];
    NSURL *url=[NSURL URLWithString:postURL];
    ASIHTTPRequest *request=[ASIHTTPRequest requestWithURL:url];
    request.defaultResponseEncoding=NSUTF8StringEncoding;
    [request setTimeOutSeconds:30];
    [request startAsynchronous];
    return request;
    
}

//消息通知
- (ASIHTTPRequest*)ASIMessage2{
    NSMutableString* postURL=[[Common alloc] GetWebAPI:@"message2.aspx"];
      [postURL appendFormat:@"location=%@",[[Common alloc] GetLocation]];
    [postURL appendFormat:@"&user-coop=%@",[[Common alloc] GetUserCoop]];
    [postURL appendFormat:@"&password-coop=%@",[[Common alloc] GetApipwd]];
    [postURL appendFormat:@"&user-id=%@",[Common GetPhone]];
//    [postURL appendFormat:@"&user-id=%@",[[Common alloc]GetMobile]];
    NSURL *url=[NSURL URLWithString:postURL];
    ASIHTTPRequest *request=[ASIHTTPRequest requestWithURL:url];
    request.defaultResponseEncoding=NSUTF8StringEncoding;
    [request setTimeOutSeconds:30];
    [request startAsynchronous];
    return request;
    
}
//消息通知历史记录
- (ASIHTTPRequest*)ASIMessagehistory:(int)start Limit:(int)limit{
    NSMutableString* postURL=[[Common alloc] GetWebAPI:@"messagehistory.aspx"];
    [postURL appendFormat:@"user-coop=%@",[[Common alloc] GetUserCoop]];
    [postURL appendFormat:@"&password-coop=%@",[[Common alloc] GetApipwd]];
    [postURL appendFormat:@"&user-id=%@",[Common GetPhone]];
//    [postURL appendFormat:@"&user-id=%@",[[Common alloc]GetMobile]];
    [postURL appendFormat:@"&start=%d",start];
    [postURL appendFormat:@"&limit=%d",limit];
    NSURL *url=[NSURL URLWithString:postURL];
    ASIHTTPRequest *request=[ASIHTTPRequest requestWithURL:url];
    request.defaultResponseEncoding=NSUTF8StringEncoding;
    [request setTimeOutSeconds:30];
    [request startAsynchronous];
    return request;
    
}
//用户反馈历史记录
- (ASIHTTPRequest*)ASIOpinionhistory:(NSString *)time   Start:(int)start Limit:(int)limit{
    NSMutableString* postURL=[[Common alloc] GetWebAPI:@"opinionhistory.aspx"];
    [postURL appendFormat:@"user-coop=%@",[[Common alloc] GetUserCoop]];
    [postURL appendFormat:@"&password-coop=%@",[[Common alloc] GetApipwd]];
//    [postURL appendFormat:@"&user-id=%@",[[Common alloc]GetMobile]];
    [postURL appendFormat:@"&user-id=%@",[Common GetPhone]];
    [postURL appendFormat:@"&start=%d",start];
    [postURL appendFormat:@"&limit=%d",limit];
     [postURL appendFormat:@"&orderby=%@",time];
    NSURL *url=[NSURL URLWithString:postURL];
    ASIHTTPRequest *request=[ASIHTTPRequest requestWithURL:url];
    request.defaultResponseEncoding=NSUTF8StringEncoding;
    [request setTimeOutSeconds:30];
    [request startAsynchronous];
    return request;
    
}
//消息推送Tocken
- (ASIHTTPRequest*)ASIIOSregister:(int)start Limit:(int)limit{
    NSMutableString* postURL=[[Common alloc] GetWebAPI:@"oiosregister.aspx"];
    [postURL appendFormat:@"user-coop=%@",[[Common alloc] GetUserCoop]];
    [postURL appendFormat:@"&password-coop=%@",[[Common alloc] GetApipwd]];
//    [postURL appendFormat:@"&cellphone=%@",[[Common alloc]GetMobile]];
    [postURL appendFormat:@"cellphone=%@",[Common GetPhone]];

     [postURL appendFormat:@"province=%@",[Common GetProvince]];
    
    
     [postURL appendFormat:@"city=%@",[Common GetCity]];
    [postURL appendFormat:@"imsi=%@",[[Common alloc] GetDeviceID]];
 [postURL appendFormat:@"token=%@",[Common getToken]];
    [postURL appendFormat:@"&start=%d",start];
    [postURL appendFormat:@"&limit=%d",limit];
    NSURL *url=[NSURL URLWithString:postURL];
    ASIHTTPRequest *request=[ASIHTTPRequest requestWithURL:url];
    request.defaultResponseEncoding=NSUTF8StringEncoding;
    [request setTimeOutSeconds:30];
    [request startAsynchronous];
    return request;
    
}

//获取版本信息
//获取版本信息
-(ASIHTTPRequest *)ASINewVersion{
    NSString* postURL=APP_URL;
    NSURL *url = [NSURL URLWithString:postURL];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    request.defaultResponseEncoding=NSUTF8StringEncoding;
    [request startAsynchronous];
    return request;
}
@end
